<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="copyright" content=""/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>酷门户商户版</title>
    <link href="<%=path%>/favicon.ico" rel="shortcut icon">
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/public.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/activity.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/style_list.css" />  
<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">	
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
<style>
	.s_dl dt{
		display:inline-block;
		float:left;
	}
	.s_dl dt img{
		margin-right:6px;
	}
	
	.s_dl dd{
		text-align:left;
	}
</style>

</head>
<body  class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
   
        <div class="container-fluid">
            <%-- <div class="row">
            	<div class="col-md-12">
				   <div class="ibox">
				    <div class="ibox-content text-right">
				      <h3>
							<span>
							<shiro:hasPermission name="bm_model_create_button">
							<button id="btn_save" type="button" class="btn btn-primary">保存分享</button>
							</shiro:hasPermission>
							</span>
						</h3>
				    </div>
				   </div>   
			 	</div> 
			 </div> 	 --%>
            <div class="row  white-bg">
	            <div class="col-md-6 text-center" style="margin-top:15px;margin-bottom:25px">
	                    <h3>酷门户信息</h3>
	                    <div class="contact-box">
	                    
	                    <div class="col-md-12">
		                     <div class="col-sm-4">
		                            <img id="micro_pic" style="width: 133px;height: 109px" src="<%=path%>/images/marketing/s_img.png" />
		                     </div>
		                     <div class="col-sm-8">
		                            <h2 id="h2"></h2>
	                                <ol id="ol_tag" class="fix" style="margin-left:5px">
	                                </ol>
	                                <p style="margin-top:8px;" id="open_time" align="left"></p>
		                     </div>
	                    </div>
	                    <div class="hr-line-dashed col-md-12"></div>
	                    <div class="col-md-12">
	                       <dl class="col-sm-6 s_dl">
	                      	  <dt><img src="<%=path%>/images/marketing/icon_addr.png" /></dt>	
	                          <dd><span id="address"></span></dd>
	                       </dl>
	                       <dl class="col-sm-6 s_dl">
	                         <dt><img src="<%=path%>/images/marketing/add_icon.png" /></dt>
	                         <dd><span id="left_phone"></span></dd>
	                       </dl>
	                    </div>
	                    <div class="hr-line-dashed col-md-12"></div>
			            <div class="tabs-container">
		                    <ul class="nav nav-tabs">
		                        <li id="bm_huoshi" class="col-md-6 text-center active"><a class="col-sm-12" data-toggle="tab" href="#tab-1" aria-expanded="false"> 活动进行时</a>
		                        </li>
		                        <li id="bm_lishihuo" class="col-md-6 text-center"><a data-toggle="tab" href="#tab-2" aria-expanded="true">历史活动</a>
		                        </li>
		                    </ul>
		                    <div class="tab-content">
		                        <div id="tab-1" class="tab-pane  active">
		                            <div class="panel-body">
			                            <ul class="surrent" id = "bm_zheng">
			                             
		                                </ul>
		                                <div id="content_empty1" hidden="" class="form-group" style="text-align:center;padding:120px 0;margin:0;">   
				                            <p>您还没有创建活动，请快创建活动吧</p>
				                            <button class="btn btn-primary" onclick="window.location.href='<%=path%>/api/bm/ui/createActivity1'">创建活动</button>
				                        </div>
		                            </div>
		                        </div>
		                        <div id="tab-2" class="tab-pane">
		                            <div class="panel-body">
			                             <ul id="bm_lishi">
			                             
			                             
		                                 </ul>
		                                 <div id="content_empty2"  hidden="" class="form-group" style="text-align:center;padding:120px 0;margin:0;">   
				                            <p>暂无历史活动</p>
				                        </div>
		                            </div>
		                            
		                        </div>
		                    </div>
		                 </div>
	                    </div>
	            </div>      
	            
	            <div class="col-md-6 white-bg" style="margin-top: 60px;padding-left:100px" >
	                   <form action="" class="form-inline" style="margin-top: 20px;">
						    <div class="form-group">
						       <label>总部名称</label>
						        <input id="right_store_name" class="form-control" style="margin-left: 30px;" type="text" oninput="reloadLeft()"/>
						    </div>
						    <%-- <div class="form-group" style="margin-left: 15px;">
						        <a id="chose_store" data-toggle="modal" href="<%=path%>/api/bm/ui/microStore" data-target="#store_modal"><font color="#1ab394">选择门店</font></a>
						    </div> --%>
					    </form> 
	                   <form action="" class="form-inline" id='upload_pic'
											enctype='multipart/form-data' style="margin-top: 20px;">
						    <div class="form-group">
						       <label>上传图片</label>
						    </div>
						    <div class="form-group" style="margin-left: 30px;">
						      <div class="x_img_sc"><img id="right_pic" style="width:100px;height:100px" src="<%=path%>/images/marketing/img_p.png"></div>
	                          <input type="file" id="x_inputfile" accept="image/gif,image/jpeg,image/x-png" name="filepath"  style=" filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.0; position:absolute; z-index:99;">
						    </div>
					   </form> 
	                   <form action="" class="form-inline" style="margin-top:20px;">
						    <div class="form-group">
						       <label class="col-sm-3 control-label">关键字</label>
						       <div class="col-sm-8">
                                    <input id="input_tag" type="text" placeholder="自助，披萨，烧烤" class="form-control" oninput="reloadLeft()" maxlength="14" onblur="checkLength(this)"> <h6 class="help-block m-b-none">输入多个关键词时请用逗号隔开</h6>
                                </div>
	                        </div>
					    </form> 
					     <form action="" class="form-inline" style="margin-top:20px;">
						    <div class="form-group">
						       <label>店铺描述</label>
						       <textarea id="input_describe" class="form-control" style="margin-left:30px;width:190.13px;height:80px;"  placeholder="营业时间" oninput="reloadLeft()" maxlength="50" onblur="checkLength(this)"></textarea>
	                        </div>
					    </form> 
					     <form action="" class="form-inline" style="margin-top:20px;">
						    <div class="form-group">
						       <label>商家地址</label>
						       <input id="right_address" class="form-control" style="margin-left: 30px;" type="text" oninput="reloadLeft()" maxlength="30" onblur="checkLength(this)">
						    </div>
					    </form> 
	                    <form action="" class="form-inline" style="margin-top:20px;">
						    <div class="form-group">
						       <label>商家电话</label>
						       <input id="right_phone" class="form-control" style="margin-left: 30px;" type="text" oninput="reloadLeft()" onkeypress="keyPress()" maxlength="11">
						    </div>
					    </form> 
	                     <div class="col-md-12 text-center" style="margin-top:30px">
	                    	  <button id="btn_save" type="button" class="btn btn-primary text-center">保存分享</button>
	                    
	                    </div>      
	                 </div>
	                    
	                   
	            </div>
	            
	            
	         <div class="row white-bg" style="margin-top:20px;padding:20px;">
		          <div class="col-sm-12">
		            <h3 class="text-center">选择门店</h3>
		          </div>
		          <div class="col-md-12" style="margin-top:30px">
			          <form role="form" action="" class="form-inline">
					    <div class="form-group col-md-1" style="margin-top:10px">
					       <label>关键字</label>
					    </div>
					    <div class="form-group col-md-3" style="margin-left:-30px">
					       <div class="input-group">
	                        <input type="text" class="form-control" id="bm_keyword" placeholder="输入关键字，支持模糊搜索">
	                        <span class="input-group-btn"> <button type="button" onclick="javascript:getStoreList();" class="btn btn-primary">搜索
	                            </button> </span>
		                   </div>
					    </div>
					    <div class="form-group col-md-8 text-right">
					       <button type="button" class="btn btn-w-m btn-primary" onclick="javascript:addToActivity();">添加到活动</button>
					    </div>
				     </form>
		          </div>
		          
		          
		          <div class="col-md-12">
		            <table class="table table-bordered" style="margin-top:20px">
                        <thead>
                        <tr>
                            <th class="col-md-1"><div class="checkbox i-checks">
                                    <label>
                                        <input id="select_all" type="checkbox" value="">
                                        <i></i>
                                    </label>
                                </div></th>
                            <th class="col-md-3">门店名称</th>
                            <th class="col-md-4">地址</th>
                            <th class="col-md-2">电话</th>
                            <th class="col-md-2 text-center">操作列</th>
                        </tr>
                        </thead>
                        <tbody id="store_list">
                          
                        
                        </tbody>
                       
                    </table>
                      <div id="content_empty3"  hidden="" class="form-group" style="text-align:center;padding:120px 0;margin:0;">   
                          <p>您还没有创建门店，请快创建门店吧</p>
                          <button class="btn btn-primary" >创建门店</button>
                      </div>
                    <div class="m_xpages storePage"  style="width: 100%; margin: 0;">
						<div class="mian">
							<span>显示行数</span> <select><option>5</option>
								<option>10</option>
								<option>20</option></select> <span>共0条</span> <span>0/0页</span> <a
								href="javascript:;" class="prev prevStore">上一页</a> <a href="javascript:;"
								class="next nextStore">下一页</a> <span>前往</span> <input type="text" value="1"
								class="text"> <span>页</span>
						</div>
					</div>
		          </div>
		          
            </div>
         </div>  
           
        
    </div>
   <div class="modal inmodal fade" id="store_modal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
               
            </div>
        </div>
    </div>

    <div hidden="" class="modal inmodal fade" id="myModal5" tabindex="-1" role="dialog"  aria-hidden="true">
	    <div class="modal-dialog modal-sm">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
	                <h4 class="modal-title">扫一扫立刻分享</h4>
	            </div>
	            <div class="modal-body text-center">
	               <div  id="qrcode"></div>
	            </div>
	        </div>
	    </div>
	</div> 
    <!-- 添加门店模态框 -->
<div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog"  aria-hidden="true">
    <div class="modal-dialog modal-sm">
       <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" onclick="javascript:closeAddModal();"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">添加门店</h4>
            </div>
            <div class="modal-body">
			    
               <form  id="commentForm" method="get" class="form-horizontal m-t">
		         <div id="form_name" class="form-group">
		             <label class="col-sm-4 control-label">门店名称</label>
		             <div class="col-sm-8">
		                 <input id="name" type="text" class="form-control" >
		             </div>
		         </div>
		         <div id="form_address" class="form-group">
		             <label class="col-sm-4 control-label">门店地址</label>
		             <div class="col-sm-8">
		                 <input id="address22" type="text" class="form-control">
		             </div>
		         </div>
		         <div class="form-group">
		             <label class="col-sm-4 control-label">电话</label>
		             <div class="col-sm-8">
		                 <input id="phone" type="text" class="form-control " >
		             </div>
		         </div>
		         
		     </form>
			     
            </div>

            <div class="modal-footer">
                <button id="add_close" onclick="javascript:closeAddModal();" type="button" class="btn btn-white" >关闭</button>
                <button onclick="javascript:editStore();" type="button" class="btn btn-primary">保存</button>
            </div>
        </div>
    </div>
</div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
   	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/marketing/lengthlimit.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>

    
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/content.min.js?v=1.0.0"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script src="<%=path%>/js/marketing/public.js"></script>
    
    <script>
    var tag="";//标签
    var business_hours="";//营业时间
    var address="";//地址
    var phone="";//联系号码
    var pic="";//图片
    var socre="";//分数
    var name="";//名称
	var access_token=$.cookie('access_token');
	var cid=$.cookie('cid');
	var uid=$.cookie('uid');
	var save_tag=false;
	var status="1";
	
	var store_id;
	
    var startIndex_store = 0;
    var pageSize_store = 5;
    var currentPage_store = 1;
    var pageCount_store = 0;
    
    var startIndex = 0;
    var pageSize = 5;
    var currentPage = 1;
    var pageCount = 0;
    var store_name="";
    
    
	
	$(function(){
		microPortal();
		getStoreList();
	});
	
	
	
	 //点击活动进行时显示
    $('#bm_huoshi').click(function(){
    	status = "1";
    	 startIndex = 0;
         pageSize = 5;
         currentPage = 1;
         pageCount = 0;
    	activting();
    });
    
    //点击历史活动显示
     $('#bm_lishihuo').click(function(){
    	 console.log("lishihuoodng");
    	 status = "0";
    	 startIndex = 0;
         pageSize = 5;
         currentPage = 1;
         pageCount = 0;
    	 activting();
    }); 
	
        $('.k_nav li').click(function(){
            $(this).addClass('on').siblings().removeClass();
            var index = $(this).index();
            $('.k_cut ul').removeClass('surrent').eq(index).addClass('surrent');
        });
    
    
        
        $('.x_popup .issue span').click(function () {
            $('.x_popup').hide();
           $('.issue').hide(); 
        });
        
        $('#btn_save').click(function(){
        	save();
        });
        //获取微门户
        function microPortal(){
        	var url = "<%=path%>/api/microportal/detail";
        	$.post(url,{
        	"access_token" : access_token,
     		"cid" : cid,
     		"uid" : uid,
        	},function(data){
        		
        		if(data.error_code == "0"){
        			
        			store_id=data.data.store_id;
        			console.log("data-------->"+data.data.name);
        			if(StringEmpty(data.data.name))
        				 $("#store_menu").val(data.data.name);
        			
        			console.log("store_id--->"+store_id);
        			activting();
        			setDataHtml(data.data); 
        		}else{
        			/* showDialog("无微门户信息"); */
        		}
        	}); 
        }
        
        
      //查询所有门店
        function bmstore(){
        	var url = "<%=path%>/store/ajaxStoreList";
        	$.post(url,{
        		"access_token" : access_token,
    			"cid" : cid,
    			"uid" : uid,
    			 "startIndex":startIndex_store,
    			 "pageSize":pageSize_store,
        	},function(data){
        		
        		if(data.status == 200){
        			var dataInfo=data.data;
        			storeHtml(dataInfo);
        			page3(data.totalCount);
        		
        		}else{
        			
        		}
        	});
        } 
        
      
        //设置html
        function setDataHtml(data){
        	
        	if(StringEmpty(data.name))
			    name=data.name;
        	if(StringEmpty(data.name)){
        		$("#h2").html(data.name);
        		$("#right_store_name").val(data.name);
        	}
			 if(StringEmpty(data.phone)){
				 var phone=(data.phone).split(",");
				 for(var i=0;i<phone.length;i++){
					 var index2=i+1;
					 var id2="#p"+index2;
					 $(id2).text(phone[i]);
				 } 
			 }
			 if(StringEmpty(data.business_hours)){
					$("#open_time").html(data.business_hours);
					$('#input_describe').val(data.business_hours);
				 }
			 $('#input_tag').val(data.tag);
			 if(StringEmpty(data.pic)){
					pic=data.pic;
					$("#micro_pic").attr("src",pic);
					$('#right_pic').attr("src",pic);
			 }
			 $('#right_phone').val(data.phone);
			 $('#right_address').val(data.address);
			 
			 
			 reloadLeft();
			 imageLoadError();
        }
        
		function save() {
			tag=$('#input_tag').val();
        	address=$("#right_address").val();
        	business_hours=$("#input_describe").val();
        	phone=$("#right_phone").val();
        	if(!validatemobile(phone)){
        		return ;
        	}
        	
			var url = "<%=path%>/api/microportal/create";
			store_name=$("#right_store_name").val();
			$.post(url, {
				"access_token" : access_token,
				"cid" : cid,
				"uid" : uid,
				"tag" : tag,
				"address" : address,
				"business_hours" : business_hours,
				"pic" : pic,
				"phone" : phone,
				"store_id" : store_id,
				"store_name":store_name,
			}, function(data) {
				if (data.status == 200) {
					if(!save_tag){
						shareActivity("<%=path%>/api/bm/ui/mobileTerminal?cid="+cid);
					}
					 save_tag=true;
					
					
				} else if(data.error_code=="20028"){
					showDialog("登陆失效，请重新登陆");
				}else{
					showDialog("保存失败");
				}
			});
		}
		$('input[type=file]').change(function () {
		    var fileCount = this.files.length;
		    if(fileCount!=0){
		    	uploadPic();
		    }
		})
		
        //上传图片
		var flag=false;
		function uploadPic() {
	        $("#upload_pic").submit(function () {  
	        	if(flag){
	        		return ;
	        	}
	        	flag=true;
	            $("#upload_pic").ajaxSubmit({
	                type: "post",
	                url: "${pageContext.request.contextPath}/api/uploadfile/file",
	                data:{"typename":"filepath"},
	                success: function (data1) {
	                	
	                	pic=data1.realSavePath;
	                	$("#micro_pic").attr("src",data1.realSavePath);
	                	$("#right_pic").attr("src",data1.realSavePath);
	                },
	                error: function (msg) {
	                    showDialog("文件上传失败");    
	                }
	            });
	            return false;
	        });
	        flag=false;
	        $("#upload_pic").submit();
		}
		
		//活动进行时
	    function activting(){    	
			console.log("store----->"+store_id);
			console.log
	    	var url = "<%=path%>/activity/activiting";
	    	console.log("state-------->"+status);
	    	$.post(url,{
	    		"cid" :cid,
	    		"uid" : uid,
	    		"access_token" :access_token,
	    		"startIndex" : startIndex,
	    		"page_size" : pageSize,
	    		"status" : status,
	    		"store_id" : store_id,
	    	},function(data){   		
	    		  
	    		console.log(data.error_code);
	    		
	    		if(status == "1"){
	    			if(data.error_code==0){
	    				activtingHtml(data.data);	
		    			page2(data.totalCount);
		    			$('#content_empty1').hide();
	    			}else{
	    				$('#content_empty1').show();
	    				$('#bm_zheng').html("");
	    			}
	    		}else{
                    if(data.error_code==0){
                    	console.log("data.totalCount------>"+data.totalCount);
    	    			historicalHtml(data.data);
    	    			page2(data.totalCount);
    	    			$('#content_empty2').hide();
	    			}else{
	    				$('#content_empty2').show();
	    				$('#bm_lishi').html("");
	    			}
	    		}
	    	});
	    }  
	    
	    //进行时活动    
	    function activtingHtml(data){       	
	    	var html = '';  
	    	if(StringEmpty(data)){
	    		for(var i=0;i<data.length;i++){    		
		    		var dataStr = data[i].start_date;    	
		    		var dayCount = data[i].effective_day;  
                    
                    
		    		html+='<div class="panel panel-default"><div class="panel-body">';
		    		
		    		html+='<div class="col-md-12" style="padding:0;">';
		    		html+='<img class="col-sm-3" style="width: 114px;height: 110px" alt="" src="'+data[i].head_pic+'">';
		    		html+='<div class="col-sm-6">';
		    		html+='<a  href="<%=path%>/view/ui/activityDetail?type=0&activity_id='+data[i].id+'"><font color="#1c84c6">'+data[i].name+'</font></a>';
		    		html+='<p>领取数'+data[i].total+'/总数'+data[i].coupon_number+'</p>';
		    		html+='<p>' +(data[i].end_time2==undefined  ||data[i].end_time2=="" ?"":"有效期至:"+data[i].end_time2)+'</p></div>';
		    		html+='<i class="text-center" style="padding:4px 6px;background:#61db4c;border-radius:3px;color:white;">进行中</i></div></div></div>';
                    
                    
		    			        	
		        }    
	    		$('#bm_zheng').html(html);	 
	    		var pagesHtml='';
				pagesHtml+='<div class="m_xpages test" style="width: 100%; margin: 0;">';
				pagesHtml+='<div class="mian">';
				pagesHtml+='<span>显示行数</span> <select><option>5</option>';
				pagesHtml+='<option>10</option>';
				pagesHtml+='<option>20</option></select> <span>共0条</span> <span>0/0页</span>';
				pagesHtml+='<a href="javascript:;" class="prev">上一页</a> <a href="javascript:;"';
				pagesHtml+='class="next">下一页</a> <span>前往</span> <input type="text" value="1"';
				pagesHtml+='class="text"> <span>页</span>';
				pagesHtml+='</div></div>';
				 $('#bm_zheng').append(pagesHtml); 
	    	}else{
	    		$('#bm_zheng').html("");	
	    		
	    	}
	    	imageLoadError();
	    }
	    
	    //历史活动
	    function historicalHtml(data){    
	    	var html = '';
	    	if(StringEmpty(data)){
	    	for(var i=0;i<data.length;i++){
            html+='<div class="panel panel-default"><div class="panel-body">';
    		html+='<div class="col-md-12">';
    		html+='<img class="col-sm-3" style="width: 114px;height: 110px" alt="" src="'+data[i].head_pic+'">';
    		html+='<div class="col-sm-4">';
    		html+='<a  href="<%=path%>/view/ui/activityDetail?type=0&activity_id='+data[i].id+'"><font color="#1c84c6">'+data[i].name+'</font></a>';
    		html+='<p>领取数'+data[i].total+'/总数'+data[i].coupon_number+'</p></div>';
    		html+='<div class="col-sm-1"></div><div class="col-sm-4 text-right">';
    		html+='<i class="text-center" style="padding:4px 6px;background:#fe7469;border-radius:3px;color:white;">已结束</i>';
	        html+='<img  class="col-sm-12" style="width:60px;height:60px;margin-top:5px" src="<%=path%>/images/marketing/ygq.png"/></div></div></div></div>';
	    	}   	
	    	$('#bm_lishi').html(html); 
	    	var pagesHtml='';
			pagesHtml+='<div class="m_xpages test" style="width: 100%; margin: 0;">';
			pagesHtml+='<div class="mian">';
			pagesHtml+='<span>显示行数</span> <select><option>5</option>';
			pagesHtml+='<option>10</option>';
			pagesHtml+='<option>20</option></select> <span>共0条</span> <span>0/0页</span>';
			pagesHtml+='<a href="javascript:;" class="prev test2">上一页</a> <a href="javascript:;"';
			pagesHtml+='class="next test2">下一页</a> <span>前往</span> <input type="text" value="1"';
			pagesHtml+='class="text"> <span>页</span>';
			pagesHtml+='</div></div>';
			$('#bm_lishi').append(pagesHtml); 
	    	}else{
	    		$('#bm_lishi').html("");
	    	}
	    	imageLoadError();
	    }
	    
	    //刷新左边uiaddress
	    function reloadLeft(){
	    	$('#open_time').html($('#input_describe').val());
	    	var tag=$('#input_tag').val().split(",");
	    	var htmlTag='';
	    	for(var i in tag){
	    		htmlTag+='<li style="float:left;margin-right:15px;">'+tag[i]+'</li>'
	    	}
	    	$('#ol_tag').html(htmlTag);
	    	$('#address').html($('#right_address').val());
	    	$('#h2').html($('#right_store_name').val());
	    	$('#left_phone').html($('#right_phone').val());
	    }
	    
	
	    
      
        //勾选后点击确定
        var address;
        
      
	    
	    
	    function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return unescape(r[2]);
			return null;
		}
	    
	    
	    function showDialog(title){
			$('#dialog_title').html('<img src="<%=path%>/images/marketing/s_tick.png"/>'+title+''); 
			$('.s_popup_delect2,.s_consum').show().delay(2000).fadeOut();
		}
	    
	    
	  //判断字符串是否为空
		function StringEmpty(content) {
			if (content == undefined || content == "" || content == null) {
				return false;
			} else {
				return true;
			}
		}
		$(".m_xpages select").change(function(){
	 		pageSize = Number($(this).val());		 		
	 		activting();
	 	});
	 	
		 $(document).on('click', '.m_xpages a.prev', function() {
		
	 	/* $(".m_xpages a.prev").click(function(){	 		 */
	 		if(currentPage > 1){
	 			currentPage--;
	 			startIndex -= pageSize;	 	
	 			activting();
	 		}
	 	});
	 	 $(document).on('click', '.m_xpages a.next', function() {
	 	/* $(".m_xpages a.next").click(function(){ */
	 		if(currentPage < pageCount){
	 			currentPage++;
	 			startIndex += pageSize;	
	 			activting();
	 		}
	 	});
	 	
	 	$(".m_xpages :text").keyup(function(e){
			if(e.keyCode==13){
				var pageGo = $(this).val();
				if(/^[0-9]+$/.test(pageGo)){
					pageGo = Number(pageGo);
					if(pageGo<1 || pageGo>pageCount){
						showDialog('请输入合法页数');
					}else if(pageGo != currentPage){
						startIndex = (pageGo -1) * pageSize ;	
						activting();
					}
				}else{
					showDialog('请输入合法页数');
				}
			}
		});

	
	function page2(totalCount) {
		
		pageCount = totalCount/pageSize;
 		if (totalCount % pageSize > 0)
 			pageCount++;
 		pageCount = parseInt(pageCount);
 		currentPage =  startIndex / pageSize + 1;
 		currentPage = parseInt(currentPage);
 		if(currentPage == 1){
 			$(".test2").addClass("pageDisable");
 		}else{
 			$(".test2").removeClass("pageDisable");
 		}
 		
 		if(currentPage == pageCount || pageCount == 0){
 			$(".test3").addClass("pageDisable");
 		}else{
 			$(".test3").removeClass("pageDisable");
 		}
 		$(".test>.mian>span:eq(1)").text('共'+totalCount+'条');
 		$(".test>.mian>span:eq(2)").text(currentPage+'/'+pageCount+'页');
	}
	
	function page3(totalCount) {
		pageCount_store = totalCount/pageSize_store;
 		if (totalCount % pageSize_store > 0)
 			pageCount_store++;
 		pageCount_store = parseInt(pageCount_store);
 		currentPage_store =  startIndex_store / pageSize_store + 1;
 		currentPage_store = parseInt(currentPage_store);
 		if(currentPage_store == 1){
 			$(".store_prev").addClass("pageDisable");
 		}else{
 			$(".store_prev").removeClass("pageDisable");
 		}
 		
 		if(currentPage_store == pageCount_store || pageCount_store == 0){
 			$(".store_next").addClass("pageDisable");
 		}else{
 			$(".store_next").removeClass("pageDisable");
 		}
 		$(".bm_store_xpages>.mian>span:eq(1)").text('共'+totalCount+'条');
 		$(".bm_store_xpages>.mian>span:eq(2)").text(currentPage_store+'/'+pageCount_store+'页');
	}
	$(".bm_store_xpages select").change(function(){
 		pageSize_store = Number($(this).val());		 		
 		bmstore();
 	});
 	
	 $(document).on('click', '.bm_store_xpages a.prev', function() {
	
 	/* $(".m_xpages a.prev").click(function(){	 		 */
 		if(currentPage_store > 1){
 			currentPage_store--;
 			startIndex_store -= pageSize_store;	 	
 			bmstore();
 		}
 	});
 	 $(document).on('click', '.bm_store_xpages a.next', function() {
 	/* $(".m_xpages a.next").click(function(){ */
 		if(currentPage_store < pageCount_store){
 			currentPage_store++;
 			startIndex_store += pageSize_store;	
 			bmstore();
 		}
 	});
 	
 	$(".bm_store_xpages :text").keyup(function(e){
		if(e.keyCode==13){
			var pageGo = $(this).val();
			if(/^[0-9]+$/.test(pageGo)){
				pageGo = Number(pageGo);
				if(pageGo<1 || pageGo>pageCount_store){
					showDialog('请输入合法页数');
				}else if(pageGo != currentPage_store){
					startIndex_store = (pageGo -1) * pageSize_store ;	
					bmstore();
				}
			}else{
				showDialog('请输入合法页数');
			}
		}
	});
	
 	
 	function colseModal(){
    	$('#store_modal').modal('hide');
    }
    
    function determineStore(){
    	$("#bm_cstore .x_CheckBox[src$='s_check.png']").each(
				function(i, d) {
					name = $(this).attr("cname");
					address= $(this).attr("address");
					phone= $(this).attr("cphone");
					store_id=this.id;
		});
	 	$('#right_store_name').val(name);
	 	$('#right_address').text(address);
	 	$('#right_phone').text(phone);
	 	reloadLeft();
	 	activting();
	 	$('#store_modal').modal('hide');
    }
    /************************************************************门店*************************************  */
    var storeStartIndex=0;
    var storePageSize=5;

    var storeList=new Array();
    //查询所有门店
    function getStoreList(){
    	//获取关键字
    	key_word = $('#bm_keyword').val();
    	var url = "<%=path%>/store/ajaxStoreList";
    	$.post(url,{
    		"access_token" : access_token,
 			"cid" : cid,
 			"uid" : uid,
 			"storeName" : key_word,
 			"startIndex" : startIndexStore,
 			"pageSize" : pageSizeStore ,
    	},function(data){
    		
    		if(data.status == 200){
    			console.log("----->"+data.data);
    			storeHtml(data.data);
    			storepage(data.totalCount);
    		}else if(data.error_code == 1){
    			
    		    $('#content_empty3').show();
    		    $('.storePage').hide();
    			errorDialog('您还未添加任何门店哦',"");
    		}
    	});
    } 
    
    
    function storeHtml(data){
    	var html = "";
    	var tag=false;
    	var flag=false;
    	
    	for(var i=0;i<data.length;i++){
    		
    		if(StringEmpty(store_id)){
    			var idsTemp=store_id.split(",");    			
    			for(var j in idsTemp){
        			
        		    console.log(idsTemp[j]);
        			if(idsTemp[j]==data[i].id){
        				storeList[data[i].id]=data[i].id;
        				flag=true;
        				break;
        			}
        		}
    		}
    		
    		
    		
    		
    		if(flag){
    			html+='<tr><td><div class="checkbox i-checks"><label class="test"><input id="'+data[i].id+'" checked="checked" type="checkbox" class="_select" value=""><i></i></label></div> </td>';

    		}else{
    			html+='<tr><td><div class="checkbox i-checks"><label class="test"><input id="'+data[i].id+'" type="checkbox" class="_select" value=""><i></i></label></div> </td>';

    		}
    		
    		html+='<td>'+data[i].name+'</td>';
    		html+='<td>'+data[i].address+'</td>';
    		html+='<td>'+data[i].phone+'</td>';
    		html+='<td class="text-center">';
    		html+='<a href="javascript:;" class="x_editor_bj" cphone="'+data[i].phone+'" caddress="'+data[i].address+'" cname="'+data[i].name+'" sid="117"><font color="#1ab394">编辑</font></a> ';
    		html+='<a class="deleted" href="javascript:;" cid="'+data[i].id+'"  onclick="javascript:deleteStoreDialog('+data[i].id+');" ><font color="#1ab394">删除</font></a></td></tr>';
    	    flag=false;
    	}
    	$('#store_list').html(html);
    	$(".i-checks").iCheck({checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green",});
     }
    $(document).on('ifChecked', '#select_all', function() {
    //全选
 //   $('#select_all').on('ifChecked', function(event){
    	$('._select').parent().addClass('checked');
    	$("._select").each(
				function(i, d) {
										
					storeList[this.id]=this.id;
					
		                 });
    	
    	console.log(storeList);
    });
    //取消全选
    $(document).on('ifUnchecked', '#select_all', function() {
    	$('._select').parent().removeClass('checked');
    	$("._select").each(
				function(i, d) {
					storeList.splice(this.id,1);
		                 });
    	
    }); 
    //勾选
    $(document).on('ifChecked', '._select', function() {
    	storeList[this.id]=this.id;
    });
    //取消勾选
    $(document).on('ifUnchecked', '._select', function() {
    	storeList.splice(this.id,1);
    });
    //添加到活动
    function addToActivity(){
    	store_id=splitIds(storeList.join(","));
    	var url = "<%=path%>/api/microportal/updateIds";
    	$.post(url,{
    		"access_token" : access_token,
 			"cid" : cid,
 			"uid" : uid,
 			"ids" : store_id,
 			
    	},function(data){
    		
    		if(data.status == 200){
    		    successDialog("添加成功");
    			activting();
    		}else if(data.error_code == 1){
    			errorDialog('您还未添加任何门店哦',"");
    		}
    		
    	});
    	
    }
   
    
    
    
    function splitIds(ids){
    	var result="";
    	var idstemp=ids.split(',');
    	for(var i in idstemp){
    		
    		if(!isNaN(idstemp[i])&&idstemp[i]>0){
    			
    			result=result+","+idstemp[i];
    		}
    	}
    	result=result.replace(",","");
    	return result;
    }
    
  //编辑时获取门店id 
    $(document).on('click','.x_editor_bj',function(){
    	flag=2;
    	storeId = $(this).attr("sid");
    	var name=$(this).attr("cname");
    	var address=$(this).attr("caddress");
    	var phone=$(this).attr("cphone");
    	console.log("---------->"+address);
    	$('#name').val(name);
    	$('#address22').val(address);
    	$('#phone').val(phone);
    	$('#myModal6').modal('show');
    });
    
  
  //编辑门店
    function editStore(){
    	//获取编辑的名称
    	var name = $('#name').val();
    	//获取编辑的地址
    	var address = $('#address22').val();
    	//获取编辑的电话
    	var phone = $('#phone').val();
    	if(StringEmpty(name)&&StringEmpty(address)){
    	var url = "<%=path%>/store/ajaxUpdateStore";
    	$.post(url,{
    		"access_token" : access_token,
			"cid" : cid,
			"uid" : uid,
			"id" : storeId,
			"name" : name,
			"address" : address,
			"phone" : phone,
    	},function(data){
    		
    		if(data.status == 200){
    			getStoreList();
    			$('#myModal6').modal('toggle');
    			successDialog("编辑成功!","");
    		}else if(data.error_code == "4"){
    			errorDialog("该门店已存在，请勿重复编辑！");
    		}else{
    			errorDialog("编辑失败，请重试！");
    		}
    	 });
    	}else if(!StringEmpty(name)){
    		$('#form_name').addClass("has-error");
        }else if(!StringEmpty(address)){
        	$('#form_address').addClass("has-error");
        }
    }
    //删除门店
    function deleteStore(id){
    	var url = "<%=path%>/store/ajaxDeleteStore";
    	$.post(url,{
    		"access_token" : access_token,
			"cid" : cid,
			"uid" : uid,
			"storeId" : id,
    	},function(data){
    		
    		if(data.status == 200){
    			getStoreList();
    			successDialog("删除成功","");
    		}else if(data.error_code == "2"){
    			errorDialog("该门店已被选用，请勿删除","");
    		}else if(data.error_code == "1"){
    			errorDialog("删除失败","");
    		}else{
    			errorDialog("系统出错","");
    		}
    	});
    }
    
    
    function deleteStoreDialog(id){
			swal({
				  title: '您确定要删除此门店吗?',
				  text: "删除后将无法恢复，请谨慎操作！",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#d33',
				  cancelButtonColor: '#3085d6',
				  confirmButtonText: '删除',
				  cancelButtonText:'取消'
				}).then(function () {
					deleteStore(id);
				})
    }
    
    function closeAddModal(){
 	   $('#myModal6').modal("hide");
    }
    
    function shareActivity(longUrl){
    	var url="<%=path%>/activity/ajaxLongUrlToShort";
		$.post(url, {
			"access_token" : access_token,
			"cid" : cid,
			"longUrl" : longUrl,
			"uid":uid,
		}, function(data) {
			if (data.status == 200) {
				var shortUrl=data.data;
				console.log(shortUrl);
           	    jQuery('#qrcode').qrcode(shortUrl);
           	    $('#myModal5').modal('show');
			}else if(data.error_code=="20028"){
				loginDialog();
        	}else{
        		errorDialog(data.message);
        	}
		});
    }
    
    
    var startIndexStore = 0;
    var pageSizeStore = 5;
    var currentPageStore = 1;
    var pageCountStore = 0;
    $(".storePage select").change(function(){
 		pageSizeStore = Number($(this).val());		 		
 		getStoreList();
 	});
 	
 	$(".storePage a.prev").click(function(){	 		
 		if(currentPageStore > 1){
 			currentPageStore--;
 			startIndexStore -= pageSizeStore;	 	
 			getStoreList();
 		}
 	});
 	
 	$(".storePage a.next").click(function(){
 		if(currentPageStore < pageCountStore){
 			currentPageStore++;
 			startIndexStore += pageSizeStore;	
 			getStoreList();
 		}
 	});
 	
 	$(".storePage :text").keyup(function(e){
		if(e.keyCode==13){
			var pageGo = $(this).val();
			if(/^[0-9]+$/.test(pageGo)){
				pageGo = Number(pageGo);
				if(pageGo<1 || pageGo>pageCountStore){
					showDialog('请输入合法页数');
				}else if(pageGo != currentPageStore){
					startIndexStore = (pageGo -1) * pageSizeStore ;	
					getStoreList();
				}
			}else{
				showDialog('请输入合法页数');
			}
		}
	});
 	
function storepage(totalCountStore) {
	pageCountStore = totalCountStore/pageSizeStore;
		if (totalCountStore % pageSizeStore > 0)
			pageCountStore++;
		pageCountStore = parseInt(pageCountStore);
		currentPageStore =  startIndexStore / pageSizeStore + 1;
		currentPageStore = parseInt(currentPageStore);
		
		if(currentPageStore == 1){
			$(".prevStore").addClass("pageDisable");
		}else{
			$(".prevStore").removeClass("pageDisable");
		}
		
		if(currentPageStore == pageCountStore || pageCountStore == 0){
			$(".nextStore").addClass("pageDisable");
		}else{
			$(".nextStore").removeClass("pageDisable");
		}
		
		$(".storePage>.mian>span:eq(1)").text('共'+totalCountStore+'条');
		$(".storePage>.mian>span:eq(2)").text(currentPageStore+'/'+pageCountStore+'页');
}

function validatemobile(mobile) {
	var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if (mobile.length == 0) {
		errorDialog('请输入手机号码！');
		return false;
	} else if (mobile.length != 11) {
		errorDialog('请输入有效的手机号码！');
		return false;
	} else if (!myreg.test(mobile)) {
		errorDialog('请输入有效的手机号码！');
		return false;
	} else {
		return true;
	}
} 
    
    </script>
    <script type="text/javascript">
    /* 微门户修改信息  双击*/
    /* 标题 */
    </script>
</body>
</html>